﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Threading;

namespace pnhBrowserTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region LOG

        delegate void consoleWriteLineDelegate(string str);

        public void log(string str)
        {
            if (textBox1.InvokeRequired)
            {
                consoleWriteLineDelegate del = new consoleWriteLineDelegate(log);
                textBox1.Invoke(del, new object[] { str + "\n" });
            }
            else
            {
                textBox1.AppendText(str + "\n");
            }
        }

        #endregion

        private void activityPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Thread newThread = new Thread(new ThreadStart(threadingActivityPage));
            newThread.IsBackground = true;
            newThread.Start();
        }

        public void threadingActivityPage()
        {
            string gamertag = "El Bluesummer";
            string url = "http://live.xbox.com/fr-FR/Activity?compareTo=" + gamertag.Replace(" ", "%20");

            log("loading... : " + url);
            string html = pnhBowserControl1.getWebPageActivity(url, gamertag);
            log("page loaded");
            MessageBox.Show("Over");
        }

        private void defaultNavigateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Thread newThread = new Thread(new ThreadStart(threadingDefaultNavigate));
            newThread.IsBackground = true;
            newThread.Start();
        }

        public void threadingDefaultNavigate()
        {
            string url = "http://live.xbox.com/fr-FR/Activity?compareTo=El%20Bluesummer";

            log("loading... : " + url);
            string html = pnhBowserControl1.navigate(url);
            log("page loaded");

            log(html);
            MessageBox.Show("Over");
        }
    }
}
